package com.sch.hospital.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;
import com.sch.hospital.domain.Result;
import com.sch.hospital.domain.Familymember;
import com.sch.hospital.service.IFamilymemberService;


/**
 * 家庭成员Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/system/familymember")
@CrossOrigin
public class FamilymemberController
{
    @Autowired
    private IFamilymemberService familymemberService;

    /**
     * 查询家庭成员列表
     */

    @GetMapping("/list")
    public Result list(Familymember familymember)
    {
        List<Familymember> list = familymemberService.selectFamilymemberList(familymember);
        return Result.success(list);
    }

    /**
     * 获取家庭成员详细信息
     */

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(familymemberService.selectFamilymemberById(id));
    }

    /**
     * 新增家庭成员
     */

    @PostMapping
    public Result add(@RequestBody Familymember familymember)
    {
        int rows = familymemberService.insertFamilymember(familymember);
        return rows > 0 ? Result.success() : Result.error("新增家庭成员失败");
    }

    /**
     * 修改家庭成员
     */

    @PutMapping
    public Result edit(@RequestBody Familymember familymember)
    {
        int rows = familymemberService.updateFamilymember(familymember);
        return rows > 0 ? Result.success() : Result.error("修改家庭成员失败");
    }

    /**
     * 删除家庭成员
     */

    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        int rows = familymemberService.deleteFamilymemberByIds(ids);
        return rows > 0 ? Result.success() : Result.error("删除家庭成员失败");
    }
}
